﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;

namespace Paint
{
    public class DrawTextStrategy : IDrawStrategy
    {
        private bool _canDraw = false;
        private System.Windows.Controls.TextBox _textBlock = null;
        private Point _previous;

        private BrushSettings _brushSettings;

        public DrawTextStrategy(BrushSettings settings)
        {
            _brushSettings = settings;
        }

        public void OnMouseDown(Canvas canvas, Point point)
        {
            _previous = point;
            _canDraw = true;


            if (_canDraw == false)
                return;

            if (_textBlock is null)
            {
                _textBlock = new System.Windows.Controls.TextBox();
                _textBlock.Foreground = _brushSettings.Color;
                _textBlock.Background = null;
                _textBlock.BorderBrush = null;

                _textBlock.TextWrapping = TextWrapping.Wrap;
                _textBlock.AcceptsReturn = true;
                _textBlock.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

                if (_brushSettings.StrokeThickness < 4)
                    _textBlock.FontSize = _brushSettings.StrokeThickness * 15;
                else if (_brushSettings.StrokeThickness >= 4 && _brushSettings.StrokeThickness < 8)
                    _textBlock.FontSize = _brushSettings.StrokeThickness * 5;
                else if (_brushSettings.StrokeThickness > 8)
                    _textBlock.FontSize = _brushSettings.StrokeThickness * 5;

                canvas.Children.Add(_textBlock);
            }

            Canvas.SetLeft(_textBlock, _previous.X);
            Canvas.SetTop(_textBlock, _previous.Y);

            _textBlock.Focus();
        }

        public void OnMouseMove(Canvas canvas, Point point)
        {
            
        }

        public void OnMouseUp(Canvas canvas, Point point)
        {
            _canDraw = false;
            _textBlock = null;
            _previous = point;
        }
    }
}
